package codeTop;

public class q415 {
    public String addStrings(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        int idx1 = num1.length()-1;
        int idx2 = num2.length()-1;
        int diverse = 0;
        while (idx1 >= 0 && idx2 >= 0) {
            int a1 = num1.charAt(idx1)-'0';
            int a2 = num2.charAt(idx2)-'0';
            int res = a1+a2+diverse;
            sb.append(res%10);
            diverse = res/10;
            idx2--;
            idx1--;
        }
        while (idx1 >= 0) {
            int res = diverse+num1.charAt(idx1)-'0';
            sb.append(res%10);
            diverse = res/10;
            idx1--;
        }
        while (idx2 >= 0) {
            int res = diverse+num2.charAt(idx2)-'0';
            sb.append(res%10);
            diverse = res/10;
            idx2--;
        }
        if (diverse != 0) {
            sb.append(diverse);
        }
        return sb.reverse().toString();
    }
}
